/**
 * @extends Ext.app.Controller
 * coder : chenfeng@xyzq.com.cn
 * date :  2014-2-12
 */
Ext.define('AutoTestApp.controller.basic.Summary', {
    extend: 'Ext.app.Controller',

    models: ['basic.EnvironmentList', 'basic.SystemInfo', 'basic.SystemConf'],
    stores: ['basic.EnvironmentList', 'basic.SystemInfo', 'basic.SystemConf'],
    views: ['basic.EnvironmentList', 'basic.SystemInfo', 'basic.SystemConf'],

    refs: [
        {
            ref: 'evnList',
            selector: 'view-basic-EnvironmentList'
        },{
            ref: 'sysInfo',
            selector: 'view-basic-SystemInfo'
        },{
            ref: 'sysConf',
            selector: 'view-basic-SystemConf'
        }

    ],

    init: function() {
        var me = this;

        me.control({
            '[iconCls=apps-btn-add]': {
                click: me.handleNewClick
            },
            '[iconCls=apps-btn-edit]': {
                click: me.handleEditClick
            },
            '[iconCls=apps-btn-delete]': {
                click: me.handleDelClick
            },
            '[iconCls=apps-btn-save]': {
                click: me.handleSaveClick
            },
            '[iconCls=apps-btn-refresh]': {
                click: me.handleRefreshClick
            }
        });
    },

	/**
     * @param {Ext.Component} component
     * @param {Ext.EventObject} e
     */
    handleNewClick : function(component, e) {
		var gp = component.ownerCt.ownerCt;
		gp.rowEditing.cancelEdit();
		var rec = Ext.create(gp.store.model.modelName, {});
		gp.store.insert(0, rec);
		gp.rowEditing.startEdit(0, 0);
    },

    handleDelClick : function(component, e) {
		var gp = component.ownerCt.ownerCt;
		var sm = gp.selModel;
		gp.rowEditing.cancelEdit();
		gp.store.remove(sm.getSelection());
		if (gp.store.getCount() > 0) {
			sm.select(0);
		}
    },

    handleEditClick: function(component, e) {
		var gp = component.ownerCt.ownerCt;
		var sm = gp.selModel;
		gp.rowEditing.cancelEdit();
		gp.rowEditing.startEdit(sm.getSelection()[0], 0);
	},

    handleSaveClick : function(component, e) {
		var store = component.ownerCt.ownerCt.store;
		store.save();
    },
 
    handleRefreshClick: function(component, e) {
		var store = component.ownerCt.ownerCt.store;
		store.load();
	}
});
